package iceberg.rules;

import iceberg.Reference;
import iceberg.constraints.ConstraintResolver;
import iceberg.constraints.Constraints;
import iceberg.constraints.IConstraintResult;
import iceberg.domain.Rule;

public class ArchitectureRule implements Rule{

	private final ConstraintResolver resolver;

	public ArchitectureRule(ConstraintResolver resolver) {
		this.resolver = resolver;
	}


	@Override
	public IConstraintResult performCheck(Reference reference) {
		Constraints constraints = resolver.getConstraints(reference.getFrom().getName());
		return constraints == null ? null : constraints.allowedToAccess(reference.getTo());
	}
}
